<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col :md="6" :sm="24">
            <a-form-item label="统计平台">
              <a-input v-model="queryParam.dto.analysisPlat" placeholder=""/>
            </a-form-item>
          </a-col>
          <!-- <a-col :md="6" :sm="24">
            <a-form-item label="pc端地址">
              <a-input v-model="queryParam.dto.pcUrl" placeholder=""/>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-item label="手机端地址">
              <a-input v-model="queryParam.dto.mobileUrl" placeholder=""/>
            </a-form-item>
          </a-col> -->
          <a-col :md="6" :sm="24">
            <span class="table-page-search-submitButtons" :style="advanced && { float: 'right', overflow: 'hidden' } || {} ">
              <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
              <a-button style="margin-left: 8px" @click="resetSearchForm()">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <div class="table-operator">
      <a-button type="primary" icon="plus" v-action:analysis:save @click="$refs.formHandle.add()">新建统计平台</a-button>
    </div>
    <s-table
      ref="table"
      size="small"
      bordered
      rowKey="id"
      :columns="columns"
      :data="loadData"
    >
      <span slot="action" slot-scope="text, record">
        <template>
          <a-tag color="orange" v-action:analysis:update @click="handleEdit(record)" >编辑</a-tag>
          <a-tag color="red" v-action:analysis:del @click="handleDelete(record)" >删除</a-tag>
          <a-tag color="red" v-action:analysis:view:page @click="view(record.pcUrl)" >查看统计</a-tag>
        </template>
      </span>

      <span slot="pcUrl" slot-scope="text">
        <template>
          <span v-if="text" v-html="$substr(text,20)"> </span>
        </template>
      </span>

      <span slot="mobileUrl" slot-scope="text">
        <template>
          <template>
            <span v-if="text" v-html="$substr(text,20)"> </span>
          </template>
        </template>
      </span>
    </s-table>
    <form-handle ref="formHandle" @ok="handleOk" />
  </a-card>
</template>

<script>
import moment from 'moment'
import formHandle from './handle'
import { page, delByPk } from '@/api/system/analysis'
import { STable } from '@/components'
// import analysis from './analysis'
export default {
  name: 'TableList',
  components: {
    STable,
    formHandle
  },
  props: {
	},
  data () {
    return {
      mdl: {},
      advanced: false,
      queryParam: {
            dto: {
            }
	    },
      columns: [
        {
         title: '统计平台',
         dataIndex: 'analysisPlat'
        },
        {
         title: 'pc端地址',
         dataIndex: 'pcUrl',
         scopedSlots: {
           customRender: 'pcUrl'
         }
        },
        {
         title: '手机端地址',
         dataIndex: 'mobileUrl',
         scopedSlots: {
           customRender: 'mobileUrl'
         }
        },
        // {
        //  title: '0:非默认 1：默认',
        //  dataIndex: 'isDefault'
        // },
        {
         title: '创建时间',
         dataIndex: 'gmtCreate',
         customRender: text => {
           if (text) return moment(text).format('YYYY-MM-DD')
         }
        },
        {
          title: '操作',
          dataIndex: 'action',
          width: '250px',
          scopedSlots: { customRender: 'action' }
        }
      ],
      loadData: parameter => {
          return page(Object.assign(parameter, this.queryParam)).then(response => {
            return response.res
          })
      }
    }
  },
  created () {
  },
  methods: {
    handleDelete (record) {
        const that = this
        this.$confirm({
        title: '操作提醒',
        content: '确定要删除吗?',
        onOk () {
             delByPk({ id: record.id }).then(response => {
                  that.$message.info(response.msg)
                  that.$refs.table.refresh()
             }).catch((response) => { that.$message.warn(response.msg) })
        },
        onCancel () {}
       })
    },
    handleEdit (record) {
      this.$refs.formHandle.edit(record)
    },
    view (pcUrl) {
       // this.$refs.analysis.open(id)
        // this.$router.push({ path: '/analysis/view?id=' + pcUrl })
       window.open(pcUrl)
    },
    handleOk () {
      this.$refs.table.refresh()
    },
    resetSearchForm () {
      this.queryParam = {
        dto: { }
      }
      this.handleOk()
    }
}
}
</script>
